import { useLocation, useNavigate } from 'react-router-dom';
import { getTabIndexByPath, getPathByTabIndex } from '@/router';
import { createNavigator } from '@/utils/navigation';

/**
 * 路由管理Hook
 * 提供路由导航、Tabbar状态管理等功能
 */
export const useRouter = () => {
    const location = useLocation();
    const navigate = useNavigate();
    
    // 当前路径
    const currentPath = location.pathname;
    
    // 当前Tab索引
    const activeTab = getTabIndexByPath(currentPath);
    
    // 创建导航器
    const navigator = createNavigator(navigate);
    
    // 切换Tab
    const switchTab = (tabIndex) => {
        const path = getPathByTabIndex(tabIndex);
        navigate(path);
    };

    return {
        currentPath,
        activeTab,
        switchTab,
        ...navigator
    };
};
